package com.example.personalcenter;

import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

/**
 * 新闻详情页
 */
public class NewsDetailActivity extends AppCompatActivity {
    
    public static final String EXTRA_NEWS_ITEM = "extra_news_item";
    
    private TextView tvTitle;
    private TextView tvAuthor;
    private TextView tvTime;
    private TextView tvContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news_detail);

        // 初始化视图
        tvTitle = findViewById(R.id.tv_detail_title);
        tvAuthor = findViewById(R.id.tv_detail_author);
        tvTime = findViewById(R.id.tv_detail_time);
        tvContent = findViewById(R.id.tv_detail_content);

        // 接收传递的数据
        NewsItem newsItem = getIntent().getParcelableExtra(EXTRA_NEWS_ITEM);
        
        if (newsItem != null) {
            // 显示数据
            tvTitle.setText(newsItem.getTitle());
            tvAuthor.setText("作者: " + newsItem.getAuthor());
            tvTime.setText(newsItem.getPublishTime());
            tvContent.setText(newsItem.getContent());
        }

        // 设置标题栏返回按钮
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
            getSupportActionBar().setTitle("新闻详情");
        }
    }

    @Override
    public boolean onSupportNavigateUp() {
        finish();
        return true;
    }
}
